<?php
require_once './model/GetBookDetailInfo.php';

class GetAmazonBookDetailInfo extends GetBookDetailInfo
{
	function __construct($detail_url, $book)
	{
		parent::__construct($detail_url, $book);
	}
	
	/**
	 * (non-PHPdoc)
	 * @see GetBookDetailInfo::setBookDetailInfo()
	 */
	function setBookDetailInfo()
	{
		$this->openUrl();
		//去掉空格和换行符
		$this->page_content = abandonBlank($this->page_content);
		$this->getBookDescribe();
		$this->getBookOtherInfo();
	}
	
	/**
	 * 获取描述信息 
	 */
	function getBookDescribe()
	{
		$pattern = '/图书描述(.*)href="#">显示更多/i';
		$describe= array();
		preg_match($pattern, $this->page_content,$describe);
		//echo ();
		//$pattern = '/<div>(.*)海报/i';
		//preg_match($pattern, $describe[1],$describe);
		//$describe[1] = str_replace('<br>', '', $describe[1]);
		require_once 'sys_fns.php';
		$describe[1] =abandonBlank($describe[1]);
		$this->setBookDescribe(strip_tags($describe[1]));
	}
	
	/**
	 * 获取图书的其他信息
	 */
	function getBookOtherInfo()
	{
		$pattern = '/基本信息(.*)ASIN:/i';
		$describe= array();
		preg_match($pattern, $this->page_content,$describe);
		$tmp = array();
		//去除html标签
		$describe[1]=strip_tags($describe[1]);
		
		//echo $describe[1];
		
		/*publishment*/
		$pattern = '/出版社:(.*)(精装|平装)/i';
		preg_match($pattern, $describe[1],$tmp);
		$this->detail_entity->_PUBLISHMENT = $tmp[1];
		
		/*pages */
		$pattern = '/(精装|平装):(.*)页语种/i';
		preg_match($pattern, $describe[1],$tmp);
		$this->setBookPages($tmp[2]);
		
		/*ISBN*/ 
		$pattern = '/ISBN:(.*)条形码:/i';
		preg_match($pattern, $describe[1],$tmp);
		@$this->setBookIbsn($tmp[1]); //有一些书籍没有ibsn
		
		/*SIZE*/
		if(strpos($describe[1], 'ISBN'))
		{
			$pattern = '/开本:(.*)ISBN:/i';
		}
		else
		{
			$pattern = '/开本:(.*)条形码:/i';
		}
		
		preg_match($pattern, $describe[1],$tmp);
		$this->setBookSize($tmp[1]);
		
	//	var_dump($tmp);
		
	}
	/**
	 * (non-PHPdoc)
	 * @see GetBookDetailInfo::getDetailBookEntity()
	 */
	function getDetailBookEntity()
	{
		$this->setBookDetailInfo();
		return $this->detail_entity;
	}
}
?>